﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace TotalApplication.Core
{
    public partial class TextEntryViewModel : BaseViewModel
    {
        #region Public Properties

        /// <summary>
        /// The label to identify what this value is for
        /// </summary>
        [ObservableProperty]
        private string? _label;

        /// <summary>
        /// The current saved value
        /// </summary>
        [ObservableProperty]
        private string? _originalText;

        /// <summary>
        /// The current non-committed value
        /// </summary>
        [ObservableProperty]
        private string? _editedText;

        /// <summary>
        /// Indicates if the current text is in editing mode
        /// </summary>
        [ObservableProperty]
        private bool _editing;

        #endregion

        #region Commands

        /// <summary>
        /// Puts the control into editing mode
        /// </summary>
        [RelayCommand]
        private void Edit()
        {
            EditedText = OriginalText;
            Editing = !Editing;
        }

        /// <summary>
        /// Cancels out of edit mode
        /// </summary>
        [RelayCommand]
        private void Cancel()
        {
            Editing = false;
        }

        /// <summary>
        /// Commits the edits and saves the value
        /// as well as goes back to non-editing mode
        /// </summary>
        [RelayCommand]
        private void Save()
        {
            OriginalText = EditedText;
            Label = OriginalText;

            Editing = false;
        }

        #endregion

        #region Constructor

        public TextEntryViewModel()
        {
            //Label = "Name";
            //OriginalText = "Tian zj is best";
            //EditedText = "Editing :)";
            //Editing = false;
        }

        #endregion
    }
}
